package com.eleadmin.order.service.impl;


import com.eleadmin.common.core.web.JsonResult;
import com.eleadmin.common.system.entity.User;
import com.eleadmin.damon.utils.results.PageResult2;
import com.eleadmin.damon.utils.utils.PinyinUtils;
import com.eleadmin.order.entity.Settings;
import com.eleadmin.order.service.SettingsService;
import org.springframework.stereotype.Service;
import com.eleadmin.order.biz.SettingsBiz;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;


/**
 * 设置项服务实现类
 * @author : Doman
 * @date : 2023-03-31 11:23:58
 * @version ：1.0
 */
@Service
public class SettingsServiceImpl /*extends ServiceImpl<SettingsMapper, Settings> */implements SettingsService {

    @Autowired
    private SettingsBiz settingsBiz;

    @Override
    public JsonResult list(PageResult2<T> page, Settings settings, User loginUser)  throws Exception{
        return settingsBiz.list(page,settings,loginUser);
    }

    @Override
    public JsonResult list(Settings settings, User loginUser) {
        return JsonResult.ok().setData(settingsBiz.list(settings,loginUser));
    }

    @Override
    public JsonResult listSel(Settings settings, User loginUser) {
        return JsonResult.ok().setData(settingsBiz.listSel(settings,loginUser));
    }

    @Override
    public JsonResult getById(String id) {
        return JsonResult.ok().setData(settingsBiz.getById(id));
    }

    @Transactional
    @Override
    public JsonResult save(Settings settings, User loginUser) {
        settings.setPinyin(PinyinUtils.ToFirstChar(settings.getName()));
        if (settingsBiz.save(settings, loginUser)) {
            return JsonResult.ok("添加成功");
        }
        return JsonResult.error("添加失败");
    }

    @Transactional
    @Override
    public JsonResult update(Settings settings, User loginUser) {
        settings.setPinyin(PinyinUtils.ToFirstChar(settings.getName()));
        if (settingsBiz.update(settings, loginUser)) {
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }

    @Transactional
    @Override
    public JsonResult remove(String id, User loginUser) {
        if (settingsBiz.remove(id, loginUser)) {
            return JsonResult.ok("删除成功");
        }
        return JsonResult.error("删除失败");
    }

}
